package edu.nf.ch02.converter;

import edu.nf.ch02.entity.User;
import edu.nf.ch02.vo.UserVO;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author wangl
 * @date 2025/10/23
 */
@Mapper
public interface UserConverter {

    UserConverter INSTANCE = Mappers.getMapper(UserConverter.class);

    @Mappings({
         @Mapping(source = "name", target = "name"),
         @Mapping(source = "age", target = "age"),
         @Mapping(source = "cash", target = "cash", numberFormat = "￥#"),
         @Mapping(source = "birth", target = "birth", dateFormat = "yyyy-MM-dd")
    })
    UserVO toUserVO(User user);

    /**
     * 反向转换,可以继承某个正向转换的方法进行反向赋值
     * @param userVO
     * @return
     */
    @InheritInverseConfiguration(name = "toUserVO")
    User toUser(UserVO userVO);
}